/**
 * 
 */

package header.refresh;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import common.CommonHttpServlet;

/**
 * url:http://127.0.0.1:8080/JSP/header/refresh/pageRefresh<br>
 * 三秒後, 自動載入新的網頁
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2001-2008
 */

public class PageRefreshServlet extends CommonHttpServlet
{
	private static final long serialVersionUID = -4699603524365409239L;

	protected void service( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
	{
		// 第一個可以用 set
		// response.setHeader( "Refresh", "3" );

		// 注意, 在這邊要用 add
		// response.addHeader( "Refresh", "URL=http://www.yahoo.com.tw/" );

		// 以下如同是上面設定的縮寫, 但是經過測試, 以上目前在環境 IE6 和 Tomcat 5.5 是無法做 refresh
		response.setHeader( "Refresh", "3;URL=http://www.yahoo.com.tw/" );

		response.setContentType( "text/html; charset=UTF-8" );
		PrintWriter writer = response.getWriter();
		writer.write( "三秒後自動轉到 yahoo 首頁" );
	}
}
